package com.example.graduationdesignbackend.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.graduationdesignbackend.constants.ResponseCode;
import com.example.graduationdesignbackend.dto.FeedbackDto;
import com.example.graduationdesignbackend.dto.PageDto;
import com.example.graduationdesignbackend.entity.Feedback;
import com.example.graduationdesignbackend.query.FeedbackQuery;
import com.example.graduationdesignbackend.res.Res;
import com.example.graduationdesignbackend.service.IFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 在线留言 前端控制器
 * </p>
 *
 * @author yuze
 * @since 2024-04-16
 */
@RestController
@SaCheckLogin
@SaCheckRole("super-admin")
@RequestMapping("/feedback")
public class FeedbackController {
    @Autowired
    private IFeedbackService feedbackService;

    @GetMapping
    public Res<Feedback> getInfo(String id){
        return Res.yuze(feedbackService.getInfo(id));
    }

    @GetMapping("/page")
    public Res<PageDto<Feedback>> getPages(FeedbackQuery feedbackQuery){
        return Res.yuze(feedbackService.getFeedbackPages(feedbackQuery));
    }
    @PostMapping
    public Res<String> createFeedback(FeedbackDto feedbackDto){
        return feedbackService.createFeedback(feedbackDto);
    }

    @DeleteMapping
    public Res<String> deleteFeedback(String id){
        Boolean remove = feedbackService.removeById(id);
        if (!remove){
            return Res.fail(ResponseCode.Fail);
        }
        return Res.yuze("删除成功！");
    }
}
